home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / handle20.zip / OPENER.ASM < prev    next >
Assembly Source File  |  1987-07-03  |  11KB  |  253 lines

  1. ;****************************************************************************
  2. ; file: opener.asm     by: Steven M. Gibson, Irvine, CA        created: 06/06/87
  3. ;****************************************************************************
  4. ;
  5. ;          * * * PUBLIC DOMAIN COPYRIGHT RELEASE NOTICE * * *
  6. ;
  7. ; THIS PROGRAM, IN BOTH SOURCE CODE AND OBJECT FORM, HAS BEEN EXPLICITLY
  8. ; PLACED INTO THE PUBLIC DOMAIN BY ITS SOLE AUTHOR AND OWNER, STEVEN GIBSON,
  9. ; OF IRVINE, CA.  IT MAY THEREFORE BE FREELY REPRODUCED, EXCHANGED, UPLOADED
  10. ; AND DOWNLOADED.   HOWEVER THE AUTHOR REQUESTS THAT THIS NOTICE OF RELEASE
  11. ; AND ORIGIN OF AUTHORSHIP BE LEFT INTACT IN THIS SOURCE CODE FILE, AND THAT
  12. ; THIS PROGRAM OR ITS DIRECT DERRIVATIVES *NOT* BE SOLD FOR PROFIT.   ALSO,
  13. ; PLEASE KEEP THE ENTIRE SET OF FILES TOGETHER AS ONE PACKAGE. ----> THANKS.
  14. ;
  15. ;****************************************************************************
  16. ;
  17. ;               About The Program: OPENER
  18. ;
  19. ; This little utility was written to determine how many handles DOS 3.x will
  20. ; ACTUALLY allow to be open at once.  It determines this with the simple
  21. ; brute-force approach of opening/creating files until the open/create fails.
  22. ; It generates files with sequential alphabetical names which are easy to
  23. ; delete:  !AAAA, !AAAB, !AAAC, !AAAD, ..., !AAAZ, !AABA, !AABB, ... 
  24. ; As this is done, it displays the file name, its sequence in the
  25. ; opening/creation process, and the handle returned by DOS to the
  26. ; open/create request.
  27. ;
  28. ; To delete all files created by this program, simply give the DOS command:
  29. ; DEL !*   ...to remove all files beginning with "!".
  30. ;
  31. ; Since it might be interesting to compare pre-DOS 3.3 opening performance,
  32. ; this program, unlike "FILES.COM", *WILL* run under DOS vers 2.0 and later.
  33. ;****************************************************************************
  34. ;
  35. ;             About These SOURCE CODE FILES:
  36. ;
  37. ;  This source code file, and the companion FILES.ASM source code file, were
  38. ;  written to be instructional, clear, and a bit tutorial in nature. As such
  39. ;  they have been commented more heavily than normal self-communication
  40. ;  would normally dictate.  I hope you will find them to be interesting,
  41. ;  useful, and not overly verbose.  They are also examples of a general
  42. ;  coding style I've found to endure quite well.  Adopt it if you like it.
  43. ;
  44. ;  NOTE: These files were created using the incredible file editor: BRIEF
  45. ;
  46. ;****************************************************************************
  47. ;
  48. ;    To make a COM file from this ASM source code:
  49. ;
  50. ;    masm opener;            <--- assemble the .asm to .obj
  51. ;    link opener;            <--- link the .obj to .exe
  52. ;    exe2bin opener opener.com    <--- convert .exe to .com
  53. ;    del opener.obj            <--- delete the intermediate debris
  54. ;    del opener.exe
  55. ;
  56. ;****************************************************************************
  57.  
  58.  
  59. ;----------------------------------------------------------------------------
  60. ;                 E Q U A T E S
  61. ;----------------------------------------------------------------------------
  62. CR            equ    0Dh
  63. LF            equ    0Ah
  64. COM_TERMINATE        equ    20h        ; .COM program termination
  65.  
  66. DOS_FUNC        equ    21h        ; Interrupt to call DOS
  67.  DOS_PRINTSTRING    equ    09h        ; Dos Sub-Function Defs
  68.  DOS_VERSION_NUMBER    equ    30h        ;    "    "
  69.  DOS_CREATE        equ    3Ch        ;    "    "
  70.   READ_AND_WRITE    equ    2        ;    "    "
  71.  
  72. VIDEO_IO        equ    10h        ; Video BIOS Interrupt Call
  73.  SET_CURSOR_POS        equ    2        ; Video Bios Sub Functions
  74.  SCROLL_UP        equ    6        ;    "    "
  75.  WRITE_TTY        equ    14        ;    "    "
  76.   NORMAL        equ    07h        ; Normal Text Video Attribute
  77.  
  78. MINIMUM_VERSION        equ    2 * 256 + 00    ; run with "2"."00" and later
  79.  
  80. ;----------------------------------------------------------------------------
  81. ;                  M A C R O S
  82. ;----------------------------------------------------------------------------
  83. zero    MACRO p1            ; this little macro is just too
  84.         xor    p1,p1        ; handy to be without.  It cleanly
  85.     ENDM                ; zeros any register.  (You'll see it
  86.                     ; a lot below)
  87.  
  88. ;----------------------------------------------------------------------------
  89. ;               C O D E    S E G M E N T
  90. ;----------------------------------------------------------------------------
  91. CODESEG    SEGMENT BYTE PUBLIC
  92.     ASSUME    CS:CODESEG, DS:CODESEG
  93.     ORG    100h
  94.  
  95. ComStart:    jmp    StartupStuff
  96.  
  97. ;----------------------------------------------------------------------------
  98. ;                   D A T A   A R E A
  99. ;----------------------------------------------------------------------------
  100. Iteration    dw    0            ; our general purpose counter
  101. ResultStr1    db    "Sequence Number:"    ; these amount to two zero-
  102. NumberStr    db    "xxxx,    Filename: "    ; terminated strings for disp.
  103. FileName    db    "!AAAA",0        ; <--- FileName str for DOS
  104. ResultStr2    db    ",    Open Handle ID:"
  105. HandleStr    db    "xxxx",CR,LF,0
  106.  
  107. WrongDosMsg    db    CR,LF,"You *NEED* DOS 2.00 or later, sorry.",CR,LF,0
  108. FailureMsg:    db    CR,LF,"The file after the last one has "
  109.         db    "FAILED to create/open", CR,LF,0
  110.  
  111.  
  112. ;----------------------------------------------------------------------------
  113. ;            P R O G R A M    C O D E    B E G I N S
  114. ;----------------------------------------------------------------------------
  115. StartupStuff:    mov    ah, DOS_VERSION_NUMBER    ; first we need to make sure
  116.         int    DOS_FUNC        ; this guy is okay to run
  117.         xchg    ah, al            ; make the number linear
  118.         cmp    ax, MINIMUM_VERSION
  119.         jae    Creations        ; yep, DOS ver 2.00 or later!
  120.  
  121.         mov    si, OFFSET WrongDosMsg    ; nope, he's using a version
  122.         Call    WriteStringToScreen    ; of DOS prior to 2.00!
  123.         int    COM_TERMINATE        ; we're not "supposed" to quit
  124.                         ; this way anymore, but it's
  125.                         ; so easy! <sigh>
  126.  
  127. ;----------------------------------------------------------------------------
  128. ;  Note:  This programs used to start out by closing any open handles, like
  129. ;  those which DOS pre-opens for us, but it still wouldn't allow any more
  130. ;  than a maximum of 252 files.  So, we'll just leave those open and proceed
  131. ;  from there....
  132. ;                  So, we open file handles until we fail at that task....
  133. ;----------------------------------------------------------------------------
  134. Creations:    inc    Iteration        ; bump our open counter
  135.         mov    ax, Iteration        ; and display this value
  136.         mov    di, OFFSET NumberStr
  137.         Call    ConvertFourDigits
  138.  
  139.         Call    AttemptToOpen        ; now ask for an "opening"
  140.         jnc    Opened            ; ah, No Carry is good...
  141.  
  142.         mov    si, OFFSET FailureMsg    ; that's all folks!
  143.         Call    WriteStringToScreen    ; show 'em we're done
  144.         int    COM_TERMINATE        ; and quit the easy way!
  145.  
  146. ;----------------------------------------------------------------------------
  147. Opened:        mov    di, OFFSET HandleStr    ; opened!... so show the
  148.         Call    ConvertFourDigits    ; returned handle number
  149.         mov    si, OFFSET ResultStr1    ; and send all this great
  150.         Call    WriteStringToScreen    ; stuff out to the screen
  151.         mov    si, OFFSET ResultStr2
  152.         Call    WriteStringToScreen
  153.  
  154.         Call    GetNextFileName        ; Now form the next filename
  155.         jmp    Creations        ; and see if we can open it!
  156.  
  157.  
  158. ;****************************************************************************
  159. ;                 S U B R O U T I N E S
  160. ;****************************************************************************
  161.  
  162. AttemptToOpen:
  163. ;----------------------------------------------------------------------------
  164. ;         Open the file: "FileName" returning the result in CY
  165. ;----------------------------------------------------------------------------
  166.         mov    ah, DOS_CREATE        ; Create or Truncate to Zero
  167.         mov    al, READ_AND_WRITE
  168.         zero    cx            ; normal file (not hidden,etc)
  169.         mov    dx, OFFSET FileName
  170.         int    DOS_FUNC
  171. Return:        ret
  172.  
  173.  
  174. GetNextFileName:
  175. ;----------------------------------------------------------------------------
  176. ;        Handle Alphabetic-Style FileName Incrementation
  177. ;----------------------------------------------------------------------------
  178.         mov    bx, OFFSET FileName+4    ; start with last char of name
  179. IncrementChar:    inc    BYTE PTR [bx]        ; bump it up
  180.         cmp    BYTE PTR [bx], "Z"    ; does it wrap?
  181.         jbe    Return            ; borrow neighbor's "ret"
  182.  
  183.         mov    BYTE PTR [bx], "A"    ; yep, return to "A"
  184.         dec    bx            ; and advance to prior char
  185.         jmp    IncrementChar        ; and increment that one now
  186.  
  187.  
  188. ConvertFourDigits:
  189. ;------------------------------------------------------------------------